package com.ams.thread.lesson4;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @author： 乐哥聊编程(全平台同号)
 */
@Slf4j
public class Example14 {
    private static ThreadLocal<Integer> threadLocal = new ThreadLocal<>();

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 20, 1000, TimeUnit.DAYS, new ArrayBlockingQueue<>(10));
        threadPoolExecutor.execute(new Runnable() {
            @Override
            public void run() {
                ThreadUtil.sleep(3000);
                log.info("当前通过execute方式执行");
            }
        });
        log.info("主线程不等待execute执行完");
        Future<?> future = threadPoolExecutor.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                ThreadUtil.sleep(3000);
                log.info("当前通过submit方式执行");
                return "submit success";
            }
        });
        log.info("主线程等待submit执行完 并获取结果::"+future.get());
        threadPoolExecutor.shutdown();
    }


}
